
package com.x52im.mall.logic.shop;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.View;

import com.x52im.rbchat.R;
import com.x52im.mall.Utility;

/*
 * 指示图片位置
 * */
public class IndicationDotList extends View
{
	private int count = 0;
	private int space = 16;
	private int index = 0;
	private Bitmap emptyDotImg;
	private Bitmap fullDotImg;
	private static int dotImgWidth = 0;
	private static int dotImgHeight = 0;

	public IndicationDotList(Context context, AttributeSet attrs)
	{
		super(context, attrs);
//		emptyDotImg = Utility.drawableToBitmap(getResources().getDrawable(R.drawable.common_mall_main_empty_dot));
//		fullDotImg = Utility.drawableToBitmap(getResources().getDrawable(R.drawable.common_mall_main_full_dot));
		emptyDotImg = Utility.drawableToBitmap(getResources().getDrawable(R.drawable.chatting_morefunc_pager_indicator_unselected_icon));
		fullDotImg = Utility.drawableToBitmap(getResources().getDrawable(R.drawable.chatting_morefunc_pager_indicator_selected_icon));
		dotImgWidth = emptyDotImg.getWidth();
		dotImgHeight = emptyDotImg.getHeight();
	}

	public int getCount()
	{
		return count;
	}

	public void setCount(int count)
	{
		this.count = count;
		invalidate();
	}

	public void setSpace(int space)
	{
		this.space = space;
	}

	public void setIndex(int index)
	{
		this.index = index;
		invalidate();
	}

	@Override
	public void draw(Canvas canvas)
	{
		// int left = getWidth() / 2 - count * dotImgWidth / 2 - (count - 1) *
		// space / 2;
		int left = (getWidth() - count * dotImgWidth - (count - 1) * space) / 2;
		int top = getHeight() - 12 - dotImgHeight / 2;
		Paint p = new Paint();
		for (int i = 0; i < count; ++i)
		{
			if (i == index)
			{
				// draw full dot
				float l = left + i * dotImgWidth + i * space;
				canvas.drawBitmap(fullDotImg, l, top, p);
			}
			else
			{
				// draw empty dot
				float l = left + i * dotImgWidth + i * space;
				canvas.drawBitmap(emptyDotImg, l, top, p);
			}
		}
	}
}
